package com.ysq.excavator.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import org.ansj.splitWord.analysis.ToAnalysis;

import com.ysq.excavator.config.ConfigInfo;
import com.ysq.excavator.util.AnsjUtil;
import com.ysq.excavator.util.LoggerUtil;

/**
 * 初始化常量的自启动servlert类
 * @author Administrator
 *
 */
public class ConstantServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void init() throws ServletException {
		
		String rootPath = getServletContext().getRealPath("/");//项目主路径
		
		AnsjUtil.rootPath = rootPath;
		
		String propertiesFile = "/WEB-INF/classes/config/properties/systemConfig.properties";
		
		String configPath = rootPath + propertiesFile;//properties 文件路径
		
		LoggerUtil.logInfo("正在初始化配置文件: " + rootPath);
		
		try {
			ConfigInfo.initConfig(configPath);
			AnsjUtil.updateAnsjSetting();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LoggerUtil.logError("init properties failed...",e);
		}
		AnsjUtil.loadStopWords(AnsjUtil.NORMAL_STOP_WORDS, 0);
		LoggerUtil.logInfo("加载配置文件完成...");
		
		ToAnalysis.parse("ansj分词初始化...");
	}
}
